<template>
	<view class="content">
		<view class="top-title">选择参会岗位</view>
		<view class="block list-block">
			<view v-for="(item,index) in list" :key="item.id" class="list-item">
				<checkbox-group @change="checkSelectItem($event, item)">
					<label>
						<checkbox :value="item.value" :checked="item.checked" />
					</label>
				</checkbox-group>
				<view @click="navigate('/page_other/job_hunting/job_detail/index?id='+item.id)">
					<view class="list-info">
						<view style="width: calc(100% - 20rpx);">
							<view class="title">{{item.jobTitle}}</view>
							<view class="address">{{item.jobAddress}}</view>
						</view>
						<view class="label-block">
							<!-- <view class="label-item" v-for="label in item.label">{{label}}</view> -->
							<view class="label-item">{{item.minEducationText}}</view>
							<view class="label-item">{{item.expRequireText}}</view>
						</view>
						<view class="wage" v-if="item.minSalary">{{item.minSalary}}-{{item.maxSalary}}<text
								class="unit">元</text></view>
						<view class="wage" v-else>面议</view>
					</view>
				</view>
			</view>
			<!-- 底部加载提示 -->
			<view v-if="list.length==total&&!more" style="text-align: center;">没有更多了哦</view>
			<view v-else style="text-align: center;">暂无数据</view>
		</view>
		<view class="all">
			<checkbox-group @change="checkSelect" class="checkbox-group">
				<label style="display: flex;">
					<checkbox :checked="checkTrue"></checkbox>
					<text>全选</text>
				</label>
			</checkbox-group>
			<view class="btn-box">
				<view class="btn" @click="confirm">确定</view>
				<view class="btn btn2" @click="back">取消</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getStorage
	} from '@/util/auth.js';
	import {
		validate
	} from '@/util/validate.js'
	import {
		insertFairCompanyApi,
		getMyPublishByFairApi
	} from '@/api/job_hunting.js';
	import {
		SplitArray
	} from '@/util/util.js';
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				recruitType: 1, //招聘会默认招全职
				checkTrue: false, //全选

				//企业角色 我的岗位数组及分页data
				//by df
				page: 1,
				limit: 100,
				more: true,
				total: 0,
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
				list: [],

				//提交
				form: {
					sId: 0, //招聘会ID
					postIds: '', //选中岗位id
				},
				rules: {
					sId: {
						name: '招聘会',
						required: true,
						validator: function(value, form, callback) {
							if (value == 0) {
								callback('请选择招聘会')
							}
							callback();
						}
					},
					postIds: {
						name: '岗位',
						required: true
					},
				},

			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			//全选
			checkSelect() {
				if (this.checkTrue == true) {
					this.checkTrue = false;
					// 遍历list数组 取消全选
					this.list.forEach(item => {
						this.$set(item, 'checked', false);

						this.form.postIds = '';
					})
				} else {
					this.checkTrue = true;
					// 遍历list数组 设置全选
					this.form.postIds = ''; //先重置 再设置全选值
					this.list.forEach(item => {
						this.$set(item, 'checked', true);

						this.form.postIds += item.id + ',';
					})
				}

			},

			checkSelectItem(e, item) {
				// 如果是取消选中，就把checked置为false,如果是选中，就给添加一个checked=true
				if (item.checked == true) {
					this.$set(item, 'checked', false);

					this.form.postIds = this.form.postIds.replace(item.id + ',', '');
				} else {
					this.$set(item, 'checked', true);

					this.form.postIds += item.id + ',';
				}
				// 过滤出数组中checked为true的项目，如果和原list长度相等，就全选显示
				let newArr = this.list.filter(item => (item.checked == true))
				if (newArr.length === this.list.length) {
					this.checkTrue = true;
				} else {
					this.checkTrue = false;
				}
			},

			//我的岗位
			getList(refresh = false) {
				uni.showLoading({
					title: '正在加载数据',
					mask: true
				})

				// if (this.loadend) {
				// 	uni.hideLoading()
				// 	return;
				// }
				// if (this.loading) return;
				var limit = this.limit;
				var page = this.page;
				// this.loading = true;
				// this.loadTitle = '';

				getMyPublishByFairApi({
					page: page,
					limit: limit,
					//recruitType: this.recruitType,
				}).then((res) => {
					uni.hideLoading()
					// let newList = res;
					// this.list = res ?? [];
					// let list = SplitArray(newList, this.personList);
					// let loadend = newList.length < limit;
					// console.log(loadend)
					// this.list = list;
					// this.page = this.page + 1;
					// this.loadend = loadend;
					// this.loading = false;
					// this.loadTitle = loadend ? '已全部加载' : '加载更多';
					let list = res || [];
					if (refresh) {
						this.list = list;

					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.page, this.limit);
				}).finally((res) => {
					this.loading = false;
					uni.hideLoading()
				})
			},

			//取消
			back() {
				this.checkTrue = false;
				// 遍历list数组 取消全选
				this.list.forEach(item => {
					this.$set(item, 'checked', false);

					this.form.postIds = '';
				})
			},

			confirm() {
				const form = JSON.parse(JSON.stringify(this.form));
				this.form.postIds = this.form.postIds.substr(0, this.form.postIds.length - 1);
				if (validate(form, this.rules)) {
					var positionNum = this.form.postIds.split(',').length;
					uni.showModal({
						title: '提示',
						content: '确定以这 ' + positionNum + ' 个岗位报名吗？报名成功后无法修改，请谨慎选择。',
						success: (modelRes) => {
							if (modelRes.confirm) {
								this.goApply(form);
							} else if (modelRes.cancel) {
								//this.utils.showToast("取消成功");
							}
						}
					});
				}

			},

			//报名招聘会
			goApply(form) {
				uni.showLoading({
					title: '提交中',
					mask: true
				})
				insertFairCompanyApi(form).then((res) => {
					uni.hideLoading()
					uni.showToast({
						title: res
					})
				})
			},

		},
		computed: {
			identity() {
				return this.$store.getters.identity
			}
		},
		onLoad(e) {
			this.form.sId = e.id;

			if (this.identity == 2) {
				this.getList(true);
			}
		},

		/**
		 * 监听用户下拉动作
		 */
		onPullDownRefresh() {
			if (this.identity == 2) {
				this.list = [];
				this.page = 1;
				this.loadend = false;
				this.getList();
				uni.stopPullDownRefresh();
			}

		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		// onReachBottom() {
		// 	if (this.identity == 2) {
		// 		this.getList();
		// 	}
		// },
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		background-color: #FAFAFA;
		// position: fixed;
		// top: 0;
		// left: 0;
		// right: 0;
		// bottom: 0;

		.top-title {
			width: 100%;
			padding: 20rpx 0rpx 20rpx 20rpx;
			font-size: 32rpx;
			font-weight: bold;
			background-color: #fff;
			margin-bottom: 20rpx;
		}

		.loadingicon {
			width: 100%;
			height: 80rpx;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: center;
		}

		.loading {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			align-items: center;
			justify-content: center;
			position: relative;
			text-align: center;
		}

		.loading .line {
			position: absolute;
			width: 450rpx;
			left: 150rpx;
			top: 50rpx;
			height: 1px;
			border-top: 1px solid #eee;
		}

		.loading .text {
			position: relative;
			display: inline-block;
			padding: 0 20rpx;
			background: #fff;
			z-index: 2;
			color: #777;
		}

		.loadingicon .loading {
			animation: load linear 1s infinite;
			font-size: 45rpx;
			color: #000;
		}

		.loadingicon {
			width: 100%;
			height: 80rpx;
		}

		.all {
			//margin: 220px 17px;
			width: 100%;
			height: 120rpx;
			padding: 0 40rpx;
			position: fixed;
			bottom: 0;
			display: flex;
			align-items: center;
			background-color: #fff;

			.checkbox-group {
				width: 160rpx;
			}

			.btn-box {
				width: calc(100% - 160rpx - 20rpx);
				display: flex;

				.btn {
					//margin-left: 150rpx;
					width: 50%;
					height: 80rpx;
					line-height: 80rpx;
					border-radius: 80rpx;
					text-align: center;
					color: #fff;
					background-color: #ff7626;
					font-size: 32rpx;
					border-left: 5px solid transparent;
					border-right: 5px solid transparent;
				}

				.btn2 {
					//margin-left: 425rpx;
					background-color: #c3c3c3;
					margin-left: 20rpx;
				}
			}

		}

		.block.list-block {
			box-shadow: none;
			display: flex;
			flex-direction: column;
			margin-bottom: 0;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				padding: 20rpx 40rpx;
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;

				.detail-info {
					width: 180rpx;
					height: 200rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;

					.name {
						width: 110rpx;
						font-size: 24rpx;
						color: #999;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						text-align: center;
						text-indent: 20rpx;
					}

					.photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.apply-btn {
						border: 1px solid #FE7526;
						border-radius: 8rpx;
						color: #FE7526;
						font-size: 24rpx;
						padding: 8rpx 28rpx;
						position: relative;
						left: 30rpx;
					}
				}

				.list-info {
					width: 100%;
					display: flex;
					flex-direction: column;
					padding-left: 40rpx;

					>view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.title {
						color: #000;
						font-weight: bold;
						font-size: 34rpx;
					}

					.address {
						width: 500rpx;
						color: #999;
						font-size: 26rpx;
						margin-top: 20rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;

					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}

					.wage {
						color: #FE7526;
						font-size: 36rpx;
						font-weight: bold;

						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
			}

			.person-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding: 0 30rpx;
				margin-bottom: 30rpx;

				.info-block,
				.job-block {
					width: 100%;
					padding: 30rpx 0;
				}

				.info-block {
					border-bottom: 1px solid #efefef;
					display: flex;
					flex-direction: row;
					align-items: center;

					.user-photo {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}

					.info {
						width: calc(100% - 120rpx);
						margin-left: 20rpx;

						.name {
							font-weight: bold;
							font-size: 34rpx;
						}

						.other {
							font-size: 24rpx;
							color: #999;
							margin-top: 14rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}
				}

				.job-block {
					display: flex;
					flex-direction: row;
					align-items: center;

					.job {
						width: calc(100% - 140rpx);
						display: flex;
						flex-direction: column;
						justify-content: center;

						.label-block {
							width: 100%;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;

							.label-item {
								background: #F4F5F7;
								color: #999;
								font-size: 24rpx;
								padding: 4rpx 10rpx;
								margin-right: 20rpx;
								margin-bottom: 20rpx;
							}
						}

						.job-content {
							width: 100%;
							font-size: 24rpx;
						}
					}

					.btn-block {
						width: 140rpx;
						display: flex;
						align-items: center;
						justify-content: center;

						.btn {
							padding: 6rpx 26rpx;
							border: 1px solid #FE7526;
							border-radius: 6rpx;
							color: #FE7526;
							font-size: 24rpx;
						}
					}
				}
			}

			.person-item:last-child {
				margin-bottom: 0;
			}

			.circle-item {
				display: flex;
				flex-direction: column;
				padding: 30rpx 30rpx 15rpx 30rpx;

				.info-block {
					display: flex;
					align-items: center;

					.user-photo {
						width: 70rpx;
						border-radius: 35rpx;
						margin-right: 15rpx;
					}

					.name {
						width: calc(100% - 70rpx - 15rpx);
						font-size: 30rpx;
					}
				}

				.content-block {
					font-size: 30rpx;
					padding: 15rpx 0 0rpx 0;

					.part-content {
						line-height: 50rpx;
						display: -webkit-box;
						overflow: hidden;
						/*超出隐藏*/
						text-overflow: ellipsis;
						/*隐藏后添加省略号*/
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 3; //想显示多少行

						.keyword {
							color: #0b93e1;
						}

						.aite {
							color: #0b93e1;
						}
					}

					.content {
						line-height: 50rpx;

						.keyword {
							color: #0b93e1;
						}

						.aite {
							color: #0b93e1;
						}
					}

					.all {
						width: 60rpx;
						;
						margin-top: 10rpx;
						color: #ff7626;
					}
				}

				.video-block {
					width: 100%;

					.video-item {
						width: 400rpx;
						height: 300rpx;
					}
				}

				.operate-block {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.time {
						color: #999999;
						font-size: 28rpx;
					}

					.operate {
						display: flex;
						align-items: center;
						height: 70rpx;

						.operate-item {
							width: 320rpx;
							height: 70rpx;
							border-radius: 6rpx;
							background-color: #616161;
							display: flex;
							flex-direction: row;

							.item {
								width: calc(100% / 2 - 1px);
								display: flex;
								flex-direction: row;
								align-items: center;
								justify-content: center;
								border-right: 1px solid rgba(0, 0, 0, .1);

								.operate-icon {
									width: 30rpx;
									margin-right: 5rpx;
								}

								.operate-name {
									font-size: 28rpx;
									color: #ccc;
								}
							}

							.item:last-child {
								border: 0;
							}
						}

						.icon {
							width: 65rpx;
							margin-left: 10rpx;
						}
					}

				}

				.comment-block {
					background-color: #f0f0f0;
					border-radius: 6rpx;
					padding: 20rpx;
					margin-top: 10rpx;
					display: flex;
					flex-direction: column;

					.like-item {
						width: 100%;
						margin: auto;

						.like-icon {
							width: 35rpx;
							position: relative;
							top: 4rpx;
						}

						.name {
							font-size: 28rpx;
							color: #0b92e0;
							margin-left: 7rpx;
						}

						.comma {
							color: #0b92e0;
						}
					}

					.divide-line {
						padding-bottom: 20rpx;
						border-bottom: 1px solid #ccc;
					}

					.comment-list {
						display: flex;
						flex-direction: column;
						padding-top: 10rpx;

						.comment-item {
							.content {
								font-size: 30rpx;
								line-height: 50rpx;
								display: -webkit-box;
								overflow: hidden;
								/*超出隐藏*/
								text-overflow: ellipsis;
								/*隐藏后添加省略号*/
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 3; //想显示多少行

								.name {
									color: #0b92e0;
								}
							}
						}
					}
				}
			}
		}
	}
</style>